<script type="text/javascript" src="<?php echo base_url(); ?>static/select2/select2.min.js" ></script>
<script type="text/javascript" src="<?php echo base_url(); ?>static/js/selectSearchGlobal.js"></script>

<script>
    function saveAtas(cType,cRequestNo) {
        $.post("<?= site_url() ?>search_global/saveAtasSik", {
            pCType              :  $('#pCType').val(),
            pSikId    			:  $('#pCtrlID').val(),
        	pNik    			:  $('#pNik').val(),
        	pVendorId    		:  $('#r_venid0').val(),
        	pVendorName    	    :  $('#r_vennama0').val(),
        	pPic    			:  $('#pPic').val(),
        	pJabatan    		:  $('#pJabatan').val(),
        	pAtasanNik    		:  $('#r_mgrid').val(),
        	pAtasanNama    	    :  $('#r_mgr').val(),
        	pNikFor    		    :  $('#r_id').val(),
        	pSdate    			:  $('#datepicker1').val(),
        	pEdate    			:  $('#datepicker2').val(),
        	pShour    			:  $('#pShour').val(),
        	pEhour    			:  $('#pEhour').val(),
        	pSminute    		:  $('#pSminute').val(),
        	pEminute    		:  $('#pEminute').val(),
            pJumlahI    		:  $('#pJumlahI').val()
        }, 
            function(data) {
                $.post("<?= site_url() ?>search_global/edit_req", {
                    cRequestNo : $('#pCtrlID').val(),
                    cType : $('#pCType').val(),
                    cTab : "saranaKerja"
                },
                function(data) {
                    $('#top').html(data); //Tampilkan di id TOP yang ada di Induk Search Global, redirect ke id top di halaman ke-2
                });
            }
        );
        
        $.post("<?= site_url() ?>search_global/edit_req", {
            cRequestNo : $('#pCtrlID').val(),
            cType : $('#pCType').val(),
            cTab : "saranaKerja"
        },
        function(data) {
            $('#top').html(data); //Tampilkan di id TOP yang ada di Induk Search Global, redirect ke id top di halaman ke-2
        });
        /*
        var nik = $(this).val();
        var rno=$('#pCtrlID').val();
        var cty=$('#pCType').val();
        var cta="saranaKerja";
	    var DataString = {
            cRequestNo : rno,
            cType : cty,
            cTab : cta
	    };
        $.ajax({
            			type: "POST",
            			url : "<?php echo site_url('search_global/edit_req')?>",
            			//dataType: 'json',
            			data: DataString,
            			success: function(data)
            			{
            				$('#top').html(data);			
            			}
            			
   		});
        */
        
        
    }
    function addBawah(cType,cRequestNo) {
        $.post("<?php echo site_url() ?>search_global/addBawahForm", {
            cType: cType,
            cRequestNo: cRequestNo
        },
        function(data) {
            $('#bawahForm').html(data);
            //$('#container').html(data);
        });
    }
    function editBawah(cType,cRequestNo,cSikjId) {
        $.post("<?= site_url() ?>search_global/editBawahForm", {
            cType: cType,
            cRequestNo: cRequestNo,
            cSikjId: cSikjId
        },
        function(data) {
            $('#bawahForm').html(data);
            //$('#container').html(data);
        });
    }
    function deleteBawah(cType,cRequestNo,cSikjId) {
        $.post("<?= site_url() ?>search_global/deleteBawahForm", {
            cType: cType,
            cRequestNo: cRequestNo,
            cSikjId: cSikjId
        },
        function(data) {
            $('#bawahForm').html(data);
            //$('#container').html(data);
        });
    }
    function cancel() {
        $.post("<?= site_url() ?>search_global", function(data) {
            window.location = '<?php echo base_url(); ?>search_global/search_global';
        });
    }
    function editSrnKrjSikSave() {
        $pJumlahI=$('#pJumlahI').val();
        var arrId=[""];
        var arrNama=[""];
        var arrPekerjaan=[""];
        var arrLantai=[""];
        var arrLocation=[""];
        var arrAccess=[""];
        var arrNamaBarang=[""];
        var arrSerial=[""];
        
        var x=0;
        for($x=0;$x<$pJumlahI;$x++){
            arrId[$x]=document.getElementById("pSikjId"+$x).value;
            arrNama[$x]=document.getElementById('pSikjName'+$x).value;
            arrPekerjaan[$x]=document.getElementById('pSikjDesc'+$x).value;
            arrLantai[$x]=document.getElementById('pSikjFloor'+$x).value;
            arrLocation[$x]=document.getElementById('pSikjLocation'+$x).value;
            arrAccess[$x]=document.getElementById('pSikjAccess'+$x).value;
            arrNamaBarang[$x]=document.getElementById('pSikjBarang'+$x).value; 
            arrSerial[$x]=document.getElementById('pSikjSn'+$x).value;
        }
        
        
        $.post("<?= site_url() ?>search_global/edit_reqSave", {
            pCType              :  $('#pCType').val(),
            pSikId    			:  $('#pCtrlID').val(),
        	pNik    			:  $('#pNik').val(),
        	//$pTypeId    		:  $('pTypeId'];
        	//$pFloorId    		:  $('pFloorId'];
        	pVendorId    		:  $('#r_venid0').val(),
        	pVendorName    	:  $('#r_vennama0').val(),
        	pPic    			:  $('#pPic').val(),
        	pJabatan    		:  $('#pJabatan').val(),
        	pAtasanNik    		:  $('#r_mgrid').val(),
        	pAtasanNama    	:  $('#r_mgr').val(),
        	pNikFor    		:  $('#r_id').val(),
        	pSdate    			:  $('#datepicker1').val(),
        	pEdate    			:  $('#datepicker2').val(),
        	pShour    			:  $('#pShour').val(),
        	pEhour    			:  $('#pEhour').val(),
        	pSminute    		:  $('#pSminute').val(),
        	pEminute    		:  $('#pEminute').val(),
            pJumlahI    		:  $('#pJumlahI').val(),
            
            //UNTUK PILIHAN TABEL BAWAH
            pSikIdBawah     : arrId,
            pSikName        : arrNama,
            pSikPekerjaan   : arrPekerjaan,
            pSikLantai      : arrLantai,
            pSikLocation    : arrLocation,
            pSikAccess      : arrAccess,
            pSikNamaBarang  : arrNamaBarang,
            pSikSerial      : arrSerial,
            
            
        }//,
        //function(data) {
        //    window.location = '<?php echo base_url(); ?>search_global';
        //}
        );
    }
</script>

<script>
//SCRIPT INI HARUS DIATAS, TIDAK BOLEH DIBAWAH
/* buat coba coba
$(document).ready(function(){
  $("#r_name").change(function(){
    alert("The text has been changed.");
  });
});
*/
$("#r_venname0").change(function() //b=0,b=1,b=2
        {   
            var venid = $(this).val();
        	var DataString = {id:venid};
            var idName=this.id.substr(9); //nilai ini penting bro, buat ngambil nama dari ID 
            	$.ajax({
            			type: "POST",
            			url : "<?php echo site_url('search_global/globals_ven_detail')?>",
            			dataType: 'json',
            			data: DataString,
            			success: function(data)
            			{
            				$("#r_venid0").val(data.DetailVen.VENDOR_ID); 
                            $("#r_vennama0").val(data.DetailVen.VENDOR_NAME);
            				$("#r_venpic0").val(data.DetailVen.PIC);			
            			}
            			
            		});
        }
);
$("#r_name").change(function()
{
    //alert(this.id.substr(2));    
	var nik = $(this).val();
	var DataString = {id:nik};
	$.ajax({
			type: "POST",
			url : "<?php echo site_url('search_global/globals_nik_detail')?>",
			dataType: 'json',
			data: DataString,
			success: function(data)
			{
				$("#r_id").val(data.DetailEmp.HR_ID);
                $("#r_nama").val(data.DetailEmp.NAME);
                $("#r_mgrid").val(data.DetailEmp.MANAGER_ID);
				$("#r_mgr").val(data.DetailEmp.MANAGER);
				$("#r_dept").val(data.DetailEmp.ORG);
				$("#r_job").val(data.DetailEmp.JOB_POSITION);														
			}
			
		});
});

</script>
<script>
	$(function() {     //HARUS TERLETAK PALING ATAS DIANTARA LAINNYA
		$("input[id^='datepicker']").datetimepicker({
			scrollInput: false,
			yearOffset:0,
			lang:'en',
			timepicker:false,
			datepicker:true,
			format:'d/m/Y',
			formatDate:'d/m/Y',
			/*minDate:'-1970/01/01',
			onGenerate:function( ct ){
				$(this).find('.xdsoft_date.xdsoft_weekend')
					.addClass('xdsoft_disabled');
			}*/
		});
	});
</script>
<script>
function addBaris(tableID) 
{
        
	var table = document.getElementById(tableID);
	//var rowCount = table.rows.length;
    var rowCount = $('#pJumlahI').val();
	if(rowCount < 10){							// limit the user from creating fields more than your limits
		var row = table.insertRow(rowCount);
		var colCount = table.rows[0].cells.length;
		for(var i=0; i<colCount; i++) {
			var newcell = row.insertCell(i);
			newcell.innerHTML = table.rows[0].cells[i].innerHTML;
		}
	}
    else{
		 alert("Maximum field per win data is 10.");
			   
	}
}
function deleteBaris(tableID) 
{
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	for(var i=0; i<rowCount; i++) {
		var row = table.rows[i];
		var chkbox = row.cells[0].childNodes[0];
		if(null != chkbox && true == chkbox.checked) {
			if(rowCount <= 1) { 						// limit the user from removing all the fields
				alert("Cannot Remove all field.");
				break;
			}
			table.deleteRow(i);
			rowCount--;
			i--;
		}
	}
}
</script>
<?php
if(!empty($cRequestNo)){
    foreach($getDetail as $a){
    	$aId   			= $a["SIK_ID"];
    	$aNik   		= $a["SIK_NIK"];
    	$aSdate   		= $a["SIK_SDATE"];
    	$aEdate   		= $a["SIK_EDATE"];
    	$aShours   		= $a["SHOURS"];
    	$aEhours   		= $a["EHOURS"];
    	$aShoure   		= $a["SHOURE"];
    	$aEhoure   		= $a["EHOURE"];
    	$aVendorId   	= $a["VENDOR_ID"];
    	$aVendorName   	= $a["VENDOR_NAME"];
    	$aVendorJabatan = $a["VENDOR_JABATAN"];
    	$aVendorPic   	= $a["VENDOR_PIC"];
    	$aUntukNik   	= $a["SIK_UNTUK_NIK"];
    
    	$aSikAtasanNik  = $a["SIK_ATASAN_NIK"];
    	$aSikAtasanName = $a["ATASANNAME"];
    	$cName			= $a["NIKNAME"];
    	$cJob			= $a["NIKORG"];
    	$cOrg			= $a["NIKJOBPOSITION"];
    }
}
?>
<div id="top" >
	<form id="formarea" role="form" method="post" action="#" class="form-horizontal">
    <input type="hidden" value="<?php echo $cRequestNo; ?>" id="pCtrlID" />
    <input type="hidden" value="<?php echo $cType; ?>" id="pCType" />
    <input type="hidden" value="<?php echo $cSikjId; ?>" id="cSikjId" />
    
	<div class="col-md-offset-0">
		<div class="col-md-11">
            <div class="panel panel-default">
				<div class="panel-heading"><h4 class="panel-title"><b class="caret"></b><b> User Login</b></h4></div>
				<div class="panel-body">
                
					<div class="col-xs-12 col-md-6">
						<div class="form-group">
							<label class="control-label col-md-3">NIK</label>
							<div class="col-md-7"><input type="text" value="<?php echo $sesNik;?>" id="pNik" class="select2 form-control input-sm" /></div>
						</div>					
						<div class="form-group">
							<label class="control-label col-md-3">Nama</label>
							<div class="col-md-3"><input type="text" value="<?php echo $sesName;?>" class="form-control input-sm" readonly=""/></div>
						</div>
					</div>
                    
					<div class="col-sm-7 col-md-6">
						<div class="form-group">
							<label class="control-label col-md-4">Departement</label>
							<div class="col-md-7"><input type="text" value="<?php echo $sesOrg;?>" class="form-control input-sm" readonly=""/></div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-4">Job Position</label>
							<div class="col-md-8"><input type="text" value="<?php echo $sesJob;?>" class="form-control input-sm" readonly=""/></div>
						</div>
					</div>
                    
				</div>
			</div>
            
			<div class="panel panel-default">
				<div class="panel-heading"><h4 class="panel-title"><b class="caret"></b><b> Requestor</b></h4></div>
				<div class="panel-body">
                
					<div class="col-xs-12 col-md-6">
						<div class="form-group">
							<label class="control-label col-md-3">Nama</label>
							<div class="col-md-7">
                                <input type="text" id="r_nama" class="select2 form-control input-sm" value="<?php echo $cName;?>" readonly=""/>
                                <input type="text" id="r_name" class="select2 form-control input-sm" value="<?php echo $cName;?>"/>
                            </div>
						</div>					
						<div class="form-group">
							<label class="control-label col-md-3">ID</label>
							<div class="col-md-3"><input type="text" value="<?php echo $aUntukNik;?>" id="r_id" class="form-control input-sm" readonly=""/></div>
						</div>
						<div class="form-group">
                            <input type="hidden" id="r_mgrid" value="<?php echo $aSikAtasanNik;?>"/>
							<label class="control-label col-md-3">Nama Atasan</label>
							<div class="col-md-9"><input type="text" value="<?php echo $aSikAtasanName;?>" id="r_mgr" class="form-control input-sm" readonly=""/></div>
						</div>
					</div>
                    
					<div class="col-sm-7 col-md-6">
						<div class="form-group">
							<label class="control-label col-md-4">Departement</label>
							<div class="col-md-7"><input type="text" value="<?php echo $cOrg;?>" id="r_dept" class="form-control input-sm" readonly=""/></div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-4">Job Position</label>
							<div class="col-md-8"><input type="text" value="<?php echo $cJob;?>" id="r_job" class="form-control input-sm" readonly=""/></div>
						</div>
					</div>
                    
				</div>
			</div>
			<div class="panel panel-default">
				<div class="panel-heading">
					<h4 class="panel-title"><b class="caret"></b><b> Request</b></h4>
				</div>
				<div class="panel-body">
					<div class="col-md-6">
						<div class="form-group">
							<label class="control-label col-md-2">Vendor</label>
							<div class="col-md-9">
                                <input type="hidden" id="jumlahVendor" value="1"/>
                                <input type="hidden" id="r_venid0" value="<?php echo $aVendorId;?>" readonly="" class="form-control input-sm"/>
                                <input id="r_vennama0" type="text" class="form-control input-sm" size="55" value="<?php echo $aVendorName;?>" readonly=""/>
                                <input type="text" id="r_venname0" value="" class="2 form-control input-sm"/>
                            </div>              
						</div>
						<div class="form-group">
							<label class="control-label col-md-2">PIC</label>
							<div class="col-md-4"><input id="pPic" type="text" class="form-control input-sm" value="<?php echo $aVendorPic; ?>" size="30"></div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-2">Jabatan</label>
							<div class="col-md-4"><input id="pJabatan" type="text" class="form-control input-sm" value="<?php echo $aVendorJabatan;?>" size="30"></div>
						</div>
					</div>
					<div class="col-md-6">
						<div class="form-group">
							<label class="control-label col-md-2">Tanggal Pekerjaan</label>
							<div class="col-md-4 form-group ">
									<div class="input-group">
										<span class="input-group-addon">From</span>
										<input type="text" class="form-control input-sm" name="date_start" id="datepicker1" value="<?php echo $aSdate; ?>"/>
									</div>
								
							</div>
							<div class="col-md-1" style="text-align:center">-</div>
							<div class="col-md-4 form-group ">
									<div class="input-group">
										<span class="input-group-addon">To</span>
										<input type="text" class="form-control input-sm" name="date_start" id="datepicker2" value="<?php echo $aEdate; ?>"/>
									</div>
								
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-2">Jam Pekerjaan</label>
							<div class="col-md-2"><input type="text" class="form-control input-sm" id="pShour" value="<?php echo $aShours;?>"/> </div>
                            <div class="col-md-1">:</div>
                            <div class="col-md-2"><input type="text" class="form-control input-sm" id="pSminute" value="<?php echo $aEhours;?>"/></div>
                            <div class="col-md-1">s/d</div>
						</div>
                        <div class="form-group">
                            <label class="control-label col-md-2"></label>
                            <div class="col-md-2"><input type="text" class="form-control input-sm" id="pEhour" value="<?php echo $aShoure;?>"/></div>
                            <div class="col-md-1">:</div>
                            <div class="col-md-2"><input type="text" class="form-control input-sm" id="pEminute" value="<?php echo $aEhoure;?>"/></div>
						</div>
					</div>
                    
                    <div class="col-md-12" style="text-align: right;">
                    <input type="button" class="btn btn-sm btn-success" value="Save Data Requestor & Request" onClick="saveAtas('<?php echo $cType;?>','<?php echo $cRequestNo; ?>')" />
                    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                    </div>
                    
					<div class="col-md-12 well well-sm" id="bawahForm">
						<div class="form-group">
							<div class="col-md-1">
                            <input type="button" class="btn btn-sm btn-warning" value="Add Form" onClick="addBawah('<?php echo $cType;?>','<?php echo $cRequestNo; ?>')" />
                            </div>
						</div>
						<div class="form-group">
							<div class="col-md-5"><label style="color:#003399">
                            </label></div>
						</div>
						<div class="form-group">
							<div class="col-md-12">
								<table class="table table-bordered table-condensed table-striped" style="margin-bottom:0px">
									<tbody>
										<tr>
											<!--<td class="tblhead" style="width:3%;text-align:center"></td>-->
											<th class="tblhead" style="width:3%;text-align:center">No.</th>
											<th class="tblhead" style="width:15%;text-align:center">Nama</th>
											<th class="tblhead" style="width:20%;text-align:center">Pekerjaan</th>
											<th class="tblhead" style="width:7%;text-align:center">Lantai</th>										
											<th class="tblhead" style="width:20%;text-align:center">Location</th>
											<th class="tblhead" style="width:8%;text-align:center">Access</th>										
											<th class="tblhead" style="width:10%;text-align:center">Nama Barang</th>
											<th class="tblhead" style="width:15%;text-align:center">S/N</th>
                                            <th class="tblhead" style="width:15%;text-align:center">Action</th>										
										</tr>
								<!--	</tbody>
								</table>
								<table id="dataTable" class="table table-bordered table-condensed table-striped">
									<tbody>-->	
                                    <?php
									   $i_job=0;
									   $no_job=1;
									   if(!empty($cRequestNo)){
									       foreach ($getDetail2 as $b){
									           $bId   	   = $b["SIKJ_ID"];
                                               $bName  	   = $b["SIKJ_NAME"];
							                   $bPekerjaan = $b["SIKJ_DESC"];
											   $bLantai    = $b["SIKJ_FLOOR"];
											   $bLocation  = $b["SIKJ_LOCATION"];
											   $bAccess    = $b["SIKJ_ACCESS"];
                                               $bBarang    = $b["SIKJ_BARANG"];
									           $bSn  	   = $b["SIKJ_SN"];
                                               
									?>
										<tr>
											<!--<td style="width:3%;"><input type="checkbox" required="required" name="chk[]" /></td>-->
											<td style="width:3%;"><?php echo $i_job+1;?></td>
											<td style="width:15%;"><input type="text" id="pSikjName<?php echo $i_job; ?>" class="form-control input-sm" value="<?php echo $bName; ?>"/></td>
											<td style="width:20%;"><input type="text" id="pSikjDesc<?php echo $i_job; ?>" class="form-control input-sm" value="<?php echo $bPekerjaan; ?>"/></td>
											<td style="width:7%;">
												<select id="pSikjFloor<?php echo $i_job; ?>" class="form-control input-sm">
												<?php 
												foreach ($getFloor as $v) 
                                                { 
                                                    $lt=$v['MST_FLOOR_DESC'];?>
													<option value="<?php echo $lt; ?>" <?php if($bLantai==$lt){?>selected=""<?php  } ?> > <?php echo $lt;?></option>
                                                <?php
												}?>
												</select>
											</td>
											<td style="width:20%;text-align:center">
                                                <input type="text" id="pSikjLocation<?php echo $i_job; ?>" class="form-control input-sm" value="<?php echo $bLocation; ?>"/>
                                            </td>
											<td style="width:8%;text-align:center">
												<select id="pSikjAccess<?php echo $i_job; ?>" class="form-control input-sm">
                                                    <option value="N" <?php if($bAccess=='N'){?>selected=""<?php } ?>>No</option>
    												<option value="Y" <?php if($bAccess=='Y'){?>selected=""<?php } ?> >Yes</option>
												</select>
											</td>
											<td style="width:10%;text-align:center">
                                                <input type="text" id="pSikjBarang<?php echo $i_job; ?>" class="form-control input-sm" value="<?php echo $bBarang; ?>"/>
                                            </td>
											<td style="width:15%;text-align:center">
                                                <input type="text" id="pSikjSn<?php echo $i_job; ?>" class="form-control input-sm" value="<?php echo $bSn; ?>"/>
                                            </td>
                                            <td>
                                            <input type="button" class="btn btn-sm btn-primary" value="Edit" onClick="editBawah('<?php echo $cType;?>','<?php echo $cRequestNo; ?>','<?php echo $bId; ?>')" />
                                            <input type="button" class="btn btn-sm btn-danger" value="Delete" onClick="deleteBawah('<?php echo $cType;?>','<?php echo $cRequestNo; ?>','<?php echo $bId; ?>')" />
                                            </td>																												
										</tr>
                                        <input type="hidden" id="pSikjId<?php echo $i_job; ?>" value="<?php echo $bId; ?>"/>
                                    <?php
    	                                   $i_job++;
    									   $no_job++;
									   }?>
                                       <input type="hidden" id="pJumlahI" value="<?php echo $i_job; ?>"/>
                                       <?php
									}
									?>
									</tbody>
								</table>
							</div>
						</div>
					</div>
					<div class="col-sm-12">				
						<div class="col-sm-2">
                            <!--<button type="button" class="btn btn-success btn-block" onclick="editSrnKrjSikSave();" >Submit</button>-->
                            
						</div>
                        <div class="col-sm-2">
                            <button type="button" class="btn btn-danger btn-block" onclick="cancel();" >Finish</button>
                        </div>
					</div>
				</div>
			</div>
		</div>
	</div>
	</form>
</div>